﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace YiJing.Model
{
    public abstract class LineFigure
    {
        private readonly Line[] _lines;

        protected LineFigure(IEnumerable<Line> bottomUpSequence, int expected)
        {
            Guard.Against<ArgumentException>(bottomUpSequence == null, "bottomUpSequence");
// ReSharper disable AssignNullToNotNullAttribute
            _lines = bottomUpSequence.ToArray();
// ReSharper restore AssignNullToNotNullAttribute
            Guard.Against<ArgumentException>(_lines.Length != expected, "bottomUpSequence");
        }

        public Line[] Lines
        {
            get { return _lines; }
        }

        public bool IsMoving
        {
            get { return _lines.Any(line => line.IsMoving); }
        }

        public IEnumerable<Line> MovedLines
        {
            get { return _lines.Select(line => line.Move()); }
        }

        public IEnumerable<Line> ToggledLines
        {
            get { return _lines.Select(line => line.Toggle()); }
        }
    }
}